from xml.dom.minidom import parseString
# create a new document
doc = parseString(u'<page/>'.encode('UTF-8'))

pagedata = doc.documentElement
# create a sect1 element
s1 = doc.createElementNS(None,u'pagedata')
# add it under the root element
pagedata.appendChild(s1)
# create a title element with a text node inside
s1.appendChild(doc.createElementNS(None,u'title'))
title = doc.createTextNode(u'Title')
s1.firstChild.appendChild(title)

heading = doc.documentElement
# create a sect1 element
s2 = doc.createElementNS(None,u'heading')
# add it under the root element
heading.appendChild(s2)
txt = doc.createTextNode(u'Heading')
s2.appendChild(txt)

subhead = doc.documentElement
# create a sect1 element
s3 = doc.createElementNS(None,'subhead')
# add it under the root element
subhead.appendChild(s3)
txt = doc.createTextNode(u'SubHeading')
s3.appendChild(txt)

content = doc.documentElement
# create a sect1 element
s4 = doc.createElementNS(None,'content')
# add it under the root element
content.appendChild(s4)
txt = doc.createTextNode(u'Content')
s4.appendChild(txt)

# write the result
print doc.toprettyxml()